// pages/draw/allApplyUser/index.js
// var common = require("../../../public.js");
// Page({
//   data: {
//     drawId: '',
//     allApplyUserInfo: {}
//   },
//   onLoad: function (options) {
//     let that = this
//     that.setData({
//       drawId: options.drawId
//     }, _ => {
//       that.getAllApplyUserList()
//     })
//   },
//   getAllApplyUserList() {
//     let that = this
//     let tempJson = {
//       drawId: that.data.drawId
//     }
//     common.post("/storeDraw/getAllApplyUserList", tempJson, function (res) {
//       if (res.status === 200) {
//         that.setData({
//           allApplyUserInfo: res.data
//         })
//       }
//     })
//   },

// })


// pages/draw/drawRank/index.js
var common = require("../../../public.js");
Page({

    data: {
        idZ: '',
        userInfo: '',
        token: '',
        drawId: '', // 抽奖id
        rankList: [],
        isAward: 1, //1中奖 0未中奖
        listBoxHeight: 0,
        pageNum: 1,
        actIndex: 0, //中奖列表
        isRequest: true, //是否发起请求
        isLoading:false,  //下拉加载
    },
    // tabs标签
    onChange(e) {
        this.setData({
            actIndex: e.detail.index,
            rankList: [],
            isRequest:true,
            pageNum:1
        }, () => {
            if (this.data.isAward == 0) {
                this.setData({
                    isAward: 1, //1中奖 0未中奖
                })
            } else {
                this.setData({
                    isAward: 0, //1中奖 0未中奖
                })
            }
            this.getRankList(true)
        })
    },
    onLoad: function (options) {
        let that = this
        wx.getStorage({
            key: 'user',
            success: function (res) {
                that.setData({
                    userInfo: res.data.user,
                    token: res.data.token,
                    drawId: options.drawId,
                }, () => {
                    that.getRankList(true)
                })
            }
        })

    },
    getRankList(refresh = false) {
        let that = this
        that.setData({
            isLoading:true
        })
        const pageNum = refresh ? 1 : this.data.pageNum + 1
        let tempJson = {
            userId: that.data.userInfo.id,
            token: that.data.token,
            drawId: that.data.drawId,
            isAward: that.data.isAward,
            pageNum
        }

        if (!this.data.isRequest) {
            return
        }
        let url = '/storeDraw/getStoreDrawUserList'
        common.wxRequest(url, "post", tempJson, 'application/x-www-form-urlencoded', function (res) {
            console.log(res.data)
            that.data.pageNum = pageNum
            if (!refresh) {  //下拉加载更多
                if (res.data.length == 0) {
                    that.setData({
                        isRequest: false
                    })

                }
                that.setData({
                    rankList: [...that.data.rankList, ...res.data]
                })
            } else {
                that.setData({
                    rankList: res.data
                })
            }

        },()=>{
            that.setData({
                isLoading:false  //加载完毕
            })
        })
    },
    // 触底
    onReachBottom() {
        this.getRankList(false)
    }

})